package com.ruoyi.system.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.Evaluating.IndicatorEvaluationScore;
import com.ruoyi.system.domain.EvaluationResultVo;
import com.ruoyi.system.domain.IndicatorEvaluationScoreVo;
import com.ruoyi.system.mapper.IndicatorEvaluationScoreMapper;
import com.ruoyi.system.service.IIndicatorEvaluationScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2024-07-18
 */
@Service
public class IndicatorEvaluationScoreServiceImpl implements IIndicatorEvaluationScoreService
{
    @Autowired
    private IndicatorEvaluationScoreMapper indicatorEvaluationScoreMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public IndicatorEvaluationScore selectIndicatorEvaluationScoreById(Long id)
    {
        return indicatorEvaluationScoreMapper.selectIndicatorEvaluationScoreById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param indicatorEvaluationScore 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<IndicatorEvaluationScore> selectIndicatorEvaluationScoreList(IndicatorEvaluationScore indicatorEvaluationScore)
    {
        return indicatorEvaluationScoreMapper.selectIndicatorEvaluationScoreList(indicatorEvaluationScore);
    }

    @Override
    public int insertIndicatorEvaluationScore(IndicatorEvaluationScoreVo indicatorEvaluationScoreVo)
    {
        int cnt=0;
        try{
            for(EvaluationResultVo vo : indicatorEvaluationScoreVo.getIndicatorScore()){
                IndicatorEvaluationScore indicatorEvaluationScore = IndicatorEvaluationScore.builder()
                        .createTime(DateUtils.getNowDate())
                        .createUser(indicatorEvaluationScoreVo.getCreator())
                        .evaluationResultId(indicatorEvaluationScoreVo.getEvaluationId())
                        .indicatorId(vo.getIndicatorId())
                        .indicatorName(vo.getIndicatorName())
                        .indicatorValue(vo.getScore())
                        .combinationWeight(vo.getCombinationWeight())
                        .objectiveWeight(vo.getObjectiveWeight())
                        .build();
                indicatorEvaluationScoreMapper.insertIndicatorEvaluationScore(indicatorEvaluationScore);
                cnt++;
            }
        } catch (Exception e){
            return cnt;
        }
        return cnt;
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param indicatorEvaluationScore 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateIndicatorEvaluationScore(IndicatorEvaluationScore indicatorEvaluationScore)
    {
        return indicatorEvaluationScoreMapper.updateIndicatorEvaluationScore(indicatorEvaluationScore);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteIndicatorEvaluationScoreByIds(Long[] ids)
    {
        return indicatorEvaluationScoreMapper.deleteIndicatorEvaluationScoreByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteIndicatorEvaluationScoreById(Long id)
    {
        return indicatorEvaluationScoreMapper.deleteIndicatorEvaluationScoreById(id);
    }

    @Override
    public int batchInsert(List<IndicatorEvaluationScoreVo> indicatorEvaluationScoreVoList) {
        List<IndicatorEvaluationScore> indicatorEvaluationScores=new ArrayList<IndicatorEvaluationScore>();
        for(IndicatorEvaluationScoreVo indicatorEvaluationScoreVo : indicatorEvaluationScoreVoList){
            for(EvaluationResultVo vo : indicatorEvaluationScoreVo.getIndicatorScore()){
                IndicatorEvaluationScore indicatorEvaluationScore = IndicatorEvaluationScore.builder()
                        .createTime(DateUtils.getNowDate())
                        .createUser(indicatorEvaluationScoreVo.getCreator())
                        .evaluationResultId(indicatorEvaluationScoreVo.getEvaluationId())
                        .indicatorId(vo.getIndicatorId())
                        .indicatorName(vo.getIndicatorName())
                        .indicatorValue(vo.getScore())
                        .combinationWeight(vo.getCombinationWeight())
                        .objectiveWeight(vo.getObjectiveWeight())
                        .build();
                //            indicatorEvaluationScoreMapper.insertIndicatorEvaluationScore(indicatorEvaluationScore);
                indicatorEvaluationScores.add(indicatorEvaluationScore);
            }
        }
        return indicatorEvaluationScoreMapper.batchInsert(indicatorEvaluationScores);
    }
}
